<?php
class tejiaControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		$url="/index.php?m=tejia";
		$limit=40;
		$start=get('per_page','i');
		$where=" siteid=".SITEID." AND status=2 ";
		$t=get('t','i');
		$time=time();
		switch($t){
			case 1://正在进行
				$where.=" AND starttime<".$time." AND endtime>".$time." ";
				break;
			case 2://即将开始
				$where.=" AND starttime>".$time;
				break;
			case 3://往期特价
				$where.=" AND endtime<".$time." ";
				break;
		}
		$url.="&t=".$t;
		$option=array(
			"start"=>$start,
			"limit"=>$limit,
			"order"=>"id DESC",
			"where"=>$where,
		);
		$rscount=true;
		$data=M("tejia")->select($option,$rscount);
		if($data){
			foreach($data as $k=>$v){
				
				$data[$k]=$v;
			}
		}
		$this->smarty->goassign(array(
			"data"=>$data
		));
		$tpl=M("pagetpl")->get("tejia","index");
		$this->smarty->display($tpl);
	}
	
	public function onSHow(){
		$id=get_post('id','i');
		$data=M("tejia")->selectRow("id=".$id);
		if(empty($data)){
			$this->goAll("数据出错",1);
		}
		$sdata=array(
			"product"=>$data,
			 
			"imgsdata"=>M("imgs")->get("tejia",$data['id'])
		);
		$this->smarty->goassign($sdata);
		$tpl=M("pagetpl")->get("tejia","show");
		$this->smarty->display($tpl);
	}
	
	
	
	
	
}
?>